﻿Imports System.Data.SqlClient
Public Class XoaMonHoc

    Private _str As String

    Sub New(ByVal str As String)
        ' TODO: Complete member initialization 
        _str = str
    End Sub

    Private Sub XoaMonHoc_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT * FROM MonHoc WHERE MonHoc_ID='" + MaMonHoc + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Me.txtMaMonHoc.Text = td.Rows(0)(0).ToString()
        Me.txtTenMonHoc.Text = td.Rows(0)(1).ToString()
        Me.txtSoTrinh.Text = td.Rows(0)(2).ToString()
        Me.txtGiangVien.Text = td.Rows(0)(3).ToString()
        con.Close()

    End Sub

    Private Sub btnXoa_Click(sender As System.Object, e As System.EventArgs) Handles btnXoa.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        Dim cmd1 As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd1.Connection = con
        cmd.CommandText = "DELETE FROM KetQua WHERE ID_MonHoc='" + MaMonHoc + "'"
        cmd1.CommandText = "DELETE FROM MonHoc Where MonHoc_ID='" + MaMonHoc + "'"
        Dim result As DialogResult
        result = MessageBox.Show("BẠN CÓ MUỐN XÓA THÔNG TIN KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            cmd.ExecuteNonQuery()
            cmd1.ExecuteNonQuery()
            MessageBox.Show("XÓA THÀNH CÔNG", "THÔNG BÁO")
            con.Close()
            Me.Close()
            Dim frm As DanhSachMonHoc = New DanhSachMonHoc()
            frm.Show()
        End If

    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
        Dim frm As DanhSachMonHoc = New DanhSachMonHoc()
        frm.Show()

    End Sub

    Private Function MaMonHoc() As String
        Throw New NotImplementedException
    End Function

End Class